package com.example.medicine.Mapper;

import com.example.medicine.Bean.book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface bookMapper {
    @Select("select * from [book]")
    List<book> getall();

    @Select("select * from [book] where id=#{id}")
    book getById(String id);

    @Insert("insert into [book](id,name,author,publisher,edition,editionTime,isbn,bookCoverName,copyRightMapName,medicalDoctor)" +
            "values(newid(),#{name},#{author},#{publisher},#{edition},#{editionTime},#{isbn},#{bookCoverName},#{copyRightMapName},#{medicalDoctor})")
    void insert(book book);

    @Insert("<script>INSERT INTO [book] (id, name, author, publisher, edition, editionTime, isbn, medicalDoctor) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(newid(),#{item.name},#{item.author},#{item.publisher},#{item.edition},#{item.editionTime},#{item.isbn},#{item.medicalDoctor})" +
            "</foreach></script>")
    void batchInsertBooks(@Param("list") List<book> books);


    //下面的更新，主要是针对图片的，想了有些办法没法实现，一堆报错，所以采用了这种笨办法
    @Update("update [book] set copyRightMapName=#{copyRightMapName} where id=#{id}")
    void updateRight(book book);

    @Update("update [book] set bookCoverName=#{bookCoverName} where id=#{id}")
    void updateCover(book book);

    @Update("update [book] set name=#{name},author=#{author},publisher=#{publisher},edition=#{edition},editionTime=#{editionTime},isbn=#{isbn},medicalDoctor=#{medicalDoctor} where id=#{id}")
    void updateNone(book book);

    @Delete("delete from [book] where id=#{id}")
    void deleteById(String id);
}
